package algorithm.poj.p1000;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLDecoder;

/**
 * 分析：
 * 
 * 实现：
 * 
 * 经验：
 * 
 * 教训：
 * 
 * 
 * @author wong.tong@gmail.com
 *
 */
public class P1163 {

	public static void main(String[] args) throws Exception {

		InputStream input = null;
		if (false) {
			input = System.in;
		} else {
			URL url = P1163.class.getResource("P1163.txt");
			File file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
			input = new FileInputStream(file);
		}
		
		BufferedReader stdin = new BufferedReader(new InputStreamReader(input));

		String line = stdin.readLine();
		int N = Integer.valueOf(line);
		int[] S = new int[N];
		for (int i = 0; i < N; i ++) {
			line = stdin.readLine();
			String[] tmp = line.trim().split(" ");
			
			int t = 0;
			for (int j = 0; j < tmp.length; j ++) {
				int s = Math.max(t, S[j]) + Integer.valueOf(tmp[j]);
				t = S[j];
				S[j] = s;
			}
		}
		
		int max = 0;
		for (int i = 0; i < N; i ++) {
			if (S[i] > max) {
				max = S[i];
			}
		}
		System.out.println(max);
	}
}